package me.dracen.service

import me.dracen.BaseApplicationTests
import me.dracen.model.UserInfo
import org.junit.Test
import org.springframework.beans.factory.annotation.Autowired

/**
 * Created by liuzinong on 2017/5/12.
 */
class UserServiceTest extends BaseApplicationTests {

    @Autowired
    UserService userService


    @Test
    void testFindAll () {
        def users = userService.findAll()

        def u1 = users.findAll {
            it ->
              it.usertype = 1
        }
        println u1
    }

    @Test
    void testFindByName () {
        def name = "test1"
        println userService.selectByName(name)

    }

    @Test
    void testSave () {
        def user = new UserInfo()
        user.usertype =2
        user.username = 'lisi'
        user.qq = '123456'
        user.enabled = 1
        userService.addUser(user)
    }

    @Test
    void testUpdate () {
        def user = userService.findById(6)
        println user
    }

    @Test
    void testFindByPage () {
        def user = new UserInfo()
        user.usertype = 1
        //user.name = "liu"
        def offset = 0,limit =10
        def list = userService.findByPage(user,offset,limit).list
        list.each {
            println it
        }
    }

    @Test
    void testGetOrSave () {
        def user = new UserInfo()
        user.usertype =2
        user.username = 'lisi'
        user.qq = '123456'
        user.enabled = 1
        def e = userService.getAndSave(user)
        println e.id
    }


}
